
Page({
  data:{
    password:'',
    phone:''
  },
  async login(){
    const params = {
      phone:this.data.phone,
      password:this.data.password
    }
    try {
      const res = await new Promise((resolve,reject)=>{
        wx.request({
          url:`http://sph-h5-api.atguigu.cn/api/user/passport/login`,
          method:'POST',
          data:params,
          // header,
          success(res){
            resolve(res.data)
            if(res.code === 200){
              wx.setStorageSync('token', res.data.data.token);
            }else{
              wx.showToast({
                title: '账号密码错误',
                icon:'error'
              })
            }
          },
          fail(error){
            reject(error)
          },
          complete(){
          }
        })
      })
      if(res.code == 200){
        wx.switchTab({
          url:'../person/person'
        })
      }
    } catch (error) {
      wx.showToast({
        title: '账号密码错误',
        icon:'error'
      })
    }
   
  }
})